package plugins.seat;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.form.FormShowParameter;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;

import java.util.EventObject;

/**
 * 动态表单插件
 */
public class SeatData extends AbstractFormPlugin implements Plugin {
    @Override
    public void afterCreateNewData(EventObject e) {
        super.afterCreateNewData(e);

        // 获取父页面的数据模型
        FormShowParameter showParameter = this.getView().getFormShowParameter();

        // 获取座位基础资料ID
        String seatId = showParameter.getCustomParam("dcb4_basedatafield_seat");
        if (seatId == null) return;

        // 查询座位信息
        QFilter qFilter = new QFilter("number", QCP.equals, seatId);
        DynamicObject goalSeat = BusinessDataServiceHelper.loadSingle("dcb4_seatdata", new QFilter[]{qFilter});


        // 给子页面模型赋值
        IDataModel parentModel = this.getView().getParentView().getModel();
        this.getModel().setValue("dcb4_basedatafield", goalSeat);
    }
}